<?php
require('../../../../lib/base.php');
$base=new base('web');
$session=$base->library('session',array('build'=>false));
if(!$session->ISSESS()){
	$helper=$base->library('helper');
	$helper->SMessage(5,domain.'view/Login.php?back='.domain.'home/account/changepwd.php',"no","登陆失效,5秒后转到登陆页");
	exit();
}
$data['menu']=$base->cache(array('tag'=>'web.header','time'=>86400));
$data['menu']=unserialize($data['menu']);
$data['HomeMenu']=$base->cache(array('tag'=>'web.home.menu','time'=>86400));
$data['HomeMenu']=unserialize($data['HomeMenu']);
$data['foot']=$base->cache(array('tag'=>'web.footer','time'=>86400));
if($base->post('submit',true)){
	$data['message']=array('result'=>false,'msg'=>array());
	$password=$base->post('password',true);
	$new=$base->post('new',true);
	$affirm=$base->post('affirm',true);
	if(strlen($password)==0){
		$data['message']['msg'][]='旧密码不可为空.';
	}else if(preg_match("/[^a-zA-Z_0-9]/",$new)>0){
		$data['message']['msg'][]='密码只可为a-z;A-Z;0-9;_的组合';
	}else if(strlen($new)<6||strlen($new)>32){
		$data['message']['msg'][]='密码长度为6-32个字符.';
	}else if(($affirm!=$new)){
		$data['message']['msg'][]='您输入的新密码和确认密码不同.';
	}else if($password==$new){
		$data['message']['msg'][]='旧密码与新密码不可相同.';
	}else{
		$member=$base->model('member');
		$affected=$member->UMember(array('set'=>array('password ='=>$new),'where'=>array('id ='=>$session->GVAR('member'),'password ='=>$password)));
		if($affected==1){
			$data['message']['result']=true;
			$data['message']['msg'][]='密码修改成功.';
		}else{
			$data['message']['msg'][]='你输入的旧密码与帐户不匹配,请注意大小写.';
		}
	}
}
$base->set($data);
$base->view('home/account/changepwd.php');
?>